package com.coderman.infosys.auth.app.facadeimpl.role;

import com.coderman.infosys.auth.api.dto.role.RoleDTO;
import com.coderman.infosys.auth.api.dto.role.RoleGroupDTO;
import com.coderman.infosys.auth.api.facade.role.RoleGroupQueryFacade;
import com.coderman.infosys.auth.api.facade.role.RoleQueryFacade;
import com.coderman.infosys.auth.app.convert.RoleConvert;
import com.coderman.infosys.auth.app.convert.RoleGroupConvert;
import com.coderman.infosys.auth.domain.bo.role.RoleBO;
import com.coderman.infosys.auth.domain.bo.role.RoleGroupBO;
import com.coderman.infosys.auth.domain.enums.errors.RoleErrorEnum;
import com.coderman.infosys.auth.domain.enums.errors.RoleGroupErrorEnum;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import com.coderman.infosys.plat.auth.common.dto.PageDTO;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * @Description:接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class RoleGroupQueryFacadeImpl implements RoleGroupQueryFacade {

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserRoleQueryGataway userRoleQueryGataway;

    @Autowired
    private UserRoleRepository userRoleRepository;

    @Override
    public ResultDataDto<PageDTO> getRoleGroupPageList(PageDTO pageDTO){
        PageBO pageBO = pageDTO.convertToBO();
        List<RoleGroupBO> roleGroupBOList = userRoleQueryGataway.getRoleGroupPageList(pageBO);
        List<RoleGroupDTO> roleGroupDTOList = RoleGroupConvert.INSTANCE.roleBOs2dtOList(roleGroupBOList);
        return ResultDataDto.success(pageDTO.initData(roleGroupDTOList,pageBO.getTotalRows()));
    }

    @Override
    public ResultDataDto<RoleGroupDTO> getByRoleGroupCode(String roleGroupCode){
        RoleGroupBO roleGroupBO = userRoleRepository.getByRoleGroupCode(roleGroupCode);
        if(roleGroupBO == null){
            return ResultDataDto.fail(RoleGroupErrorEnum.ROLE_GROUP_NOTFUND_ERROR);
        }
        return  ResultDataDto.success(RoleGroupConvert.INSTANCE.bO2dto(roleGroupBO));
    }

    @Override
    public ResultDataDto<List<RoleGroupDTO>> search(String search){
        List<RoleGroupBO> roleGroupBOList = userRoleQueryGataway.searchRoleGroup(search);
        return  ResultDataDto.success(RoleGroupConvert.INSTANCE.roleBOs2dtOList(roleGroupBOList));
    }

}